<?php
class Util
{
	static public function RandomString($length=10,$uc=TRUE,$n=TRUE,$sc=FALSE){
		$source = 'abcdefghijklmnopqrstuvwxyz';
		if($uc==1) $source .= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
		if($n==1) $source .= '1234567890';
		if($sc==1) $source .= '|@#~$%()=^*+[]{}-_';
		if($length>0){
			$rstr = "";
			$source = str_split($source,1);
			for($i=1; $i<=$length; $i++){
				mt_srand((double)microtime() * 1000000);
				$num = mt_rand(1,count($source));
				$rstr .= $source[$num-1];
			}

		}
		return $rstr;
	}
	
	static public function extensionFile($filename){
	    return substr(strrchr($filename, '.'), 1);
	}
	
	static public function ObtenerSession(){
		if(isset($_SESSION['usuario'])){
			return $_SESSION['usuario'];
		}
		
		return null;
	}
	
	static public function EnvialMail($to ,$subject ,$message, $cabeceras = ""){
		$para      = Util::ObtenerCorreo($to);
		$titulo = $subject;
						
		if($cabeceras==""){				
			$headers  = 'MIME-Version: 1.0' . "\r\n";
			$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";		
			// Additional headers
			$headers .= 'From: '.DESCRIPTION_MAIL_FROM.' <'.MAIL_FROM.'>' . "\r\n";
			$headers .= 'Bcc: jolivera@esan.edu.pe';					
			$cabeceras = $headers;				
		}
		//echo $cabeceras;
		
		mail($para, $titulo, $message, $cabeceras);	
		//exit();
	}

	static public function EnvialMail2($to ,$subject ,$message, $copiaOculta = ""){
		$para      = Util::ObtenerCorreo($to);
		$titulo = $subject;
						
			$headers  = 'MIME-Version: 1.0' . "\r\n";
			$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";		
			// Additional headers
			$headers .= 'From: '.DESCRIPTION_MAIL_FROM.' <'.MAIL_FROM.'>' . "\r\n";
			$headers .= 'Bcc: jolivera@esan.edu.pe'.$copiaOculta . "\r\n";					
			$cabeceras = $headers;				

		mail($para, $titulo, $message, $cabeceras);	
	}
	
	static public function ObtenerCorreo($correo){	
		if(DESARROLLO == '1'){
			return MAIL_DESARROLLO;
		}else{
			return $correo;
		}
	}
	
	static public function FormatoHtml($value){
		return htmlentities(utf8_decode($value));
		//return utf8_encode(htmlentities($value));
		//return htmlentities($value);
		//return $value;
	}
}
?>